//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "AbcdSquared.h"
using namespace Cephei::QL::Termstructures::Volatility;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (Double a, Double b, Double c, Double d, Double T, Double S) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phAbcdSquared = NULL;
#endif
        QuantLib::Real _a = (QuantLib::Real)ValueHelper::Convert (a);
        QuantLib::Real _b = (QuantLib::Real)ValueHelper::Convert (b);
        QuantLib::Real _c = (QuantLib::Real)ValueHelper::Convert (c);
        QuantLib::Real _d = (QuantLib::Real)ValueHelper::Convert (d);
        QuantLib::Time _T = (QuantLib::Time)ValueHelper::Convert (T);
        QuantLib::Time _S = (QuantLib::Time)ValueHelper::Convert (S);
        _ppAbcdSquared = new boost::shared_ptr<QuantLib::AbcdSquared> (new QuantLib::AbcdSquared ( _a,  _b,  _c,  _d,  _T,  _S ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (boost::shared_ptr<QuantLib::AbcdSquared>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAbcdSquared = NULL;
#endif
	_ppAbcdSquared = &childNative;
    
}
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (QuantLib::AbcdSquared& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phAbcdSquared = NULL;
#endif
	_ppAbcdSquared = new boost::shared_ptr<QuantLib::AbcdSquared> (&childNative);
    
    _AbcdSquaredOwner = owner;
    
}

Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (CAbcdSquared^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAbcdSquared = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAbcdSquared = new boost::shared_ptr<QuantLib::AbcdSquared> (copy->GetShared());
        
    }
}
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAbcdSquared = NULL;
#endif
	if (!t->IsSubclassOf(CAbcdSquared::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (QuantLib::Handle<QuantLib::AbcdSquared>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAbcdSquared = &childNative;
	_ppAbcdSquared = &static_cast<boost::shared_ptr<QuantLib::AbcdSquared>>(childNative.currentLink());
    
    _AbcdSquaredOwner = owner;
}
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (QuantLib::Handle<QuantLib::AbcdSquared> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAbcdSquared = &childNative;
	_ppAbcdSquared = &static_cast<boost::shared_ptr<QuantLib::AbcdSquared>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Volatility::CAbcdSquared::CAbcdSquared (QuantLib::AbcdSquared childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAbcdSquared = NULL;
#endif
	_ppAbcdSquared = new boost::shared_ptr<QuantLib::AbcdSquared> (new QuantLib::AbcdSquared (childNative));
    
}
#endif

Cephei::QL::Termstructures::Volatility::CAbcdSquared::~CAbcdSquared ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppAbcdSquared != NULL)
    {
	    delete _ppAbcdSquared;
        _ppAbcdSquared = NULL;
    }
}
Cephei::QL::Termstructures::Volatility::CAbcdSquared::!CAbcdSquared ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppAbcdSquared != NULL)
    {
	    delete _ppAbcdSquared;
    }
}
QuantLib::AbcdSquared& Cephei::QL::Termstructures::Volatility::CAbcdSquared::GetReference ()
{
    if (_ppAbcdSquared == NULL) throw gcnew NativeNullException ();
	return **_ppAbcdSquared;
}
boost::shared_ptr<QuantLib::AbcdSquared>& Cephei::QL::Termstructures::Volatility::CAbcdSquared::GetShared ()
{
    if (_ppAbcdSquared == NULL) throw gcnew NativeNullException ();
	return *_ppAbcdSquared;
}
QuantLib::AbcdSquared* Cephei::QL::Termstructures::Volatility::CAbcdSquared::GetPointer ()
{
    if (_ppAbcdSquared == NULL) throw gcnew NativeNullException ();
	return &**_ppAbcdSquared;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AbcdSquared>& Cephei::QL::Termstructures::Volatility::CAbcdSquared::GetHandle ()
{
	if (_phAbcdSquared == NULL)
	{
		_phAbcdSquared = new Handle<QuantLib::AbcdSquared> (*_ppAbcdSquared);
	}
	return *_phAbcdSquared;
}
#endif
bool Cephei::QL::Termstructures::Volatility::CAbcdSquared::HasNative () 
{
	return (_ppAbcdSquared != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Termstructures::Volatility::IAbcdSquared^ Cephei::QL::Termstructures::Volatility::CAbcdSquared_Factory::Create (Double a, Double b, Double c, Double d, Double T, Double S)
{
    return gcnew CAbcdSquared ( a,  b,  c,  d,  T,  S);
}
